﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.IO;
using System.Web;
using System.Text.RegularExpressions;
using System.Linq;

/// <summary>
/// Summary description for Email
/// </summary>
public class Email
{
    public Email()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public static string Table = "style=\"border:solid 1px #000000;font-family:Tahoma;font-size:12px; border-collapse: collapse;\"";//table
    public static string TableHeader = "style=\"background-color:#17365D;color:#FFFFFF;border-bottom:solid 1px #000000;font-weight:bold;\"";//header
    public static string TableRow = "style=\"border-bottom:solid 1px #000000;\"";//row
    public static string TableCell = "style=\"border-right:solid 1px #000000;border-bottom:solid 1px #000000;\"";//cell
    public static string TableFooter = "style=\"background-color:#17365D;color:#FFFFFF\"";//footer
    public static string TableSubTotal = "style=\"border-bottom: solid 1px #000000;vertical-align:middle; font-size:8pt; font-weight:bold; height:20px;\"";//subtotal
    public static string OuterTable = "style=\"font-family:Tahoma;\"";// outer table
    public static string TableSubTotalFixedFont = "style=\"border-bottom: solid 1px #000000;vertical-align:middle; font-size:8pt; font-weight:bold; height:20px;\"";
    public static string OuterTableHeader = "style=\"background-color:#17365D;color:#FFFFFF;border:solid 1px #FFFFFF;font-weight:bold;\"";//header


    public static object[] GetTableStyle()
    {
        //any change here should also be duplicated in Schedular
        object[] objRet = new object[8];
        objRet[0] = "style=\"border:solid 0px #000000;font-family:Calibri;font-size:14px;\"";//table
        objRet[1] = "style=\"background-color:#17365D;color:#FFFFFF;border-bottom:solid 1px #000000;font-weight:bold;\"";//header
        objRet[2] = "style=\"border-bottom:solid 1px #000000;\"";//row
        objRet[3] = "style=\"border-right:solid 1px #000000;border-bottom:solid 1px #000000;\"";//cell
        objRet[4] = "style=\"background-color:#17365D;color:#FFFFFF\"";//footer
        objRet[5] = "style=\"border-bottom: solid 1px #000000;vertical-align:middle; font-size:8pt; font-weight:bold; height:20px;\"";//subtotal
        objRet[6] = "style=\"font-family:Calibri;\"";// outer table
        objRet[7] = "style=\"border-bottom: solid 1px #000000;vertical-align:middle;font-weight:bold; height:20px;\"";//subtotal
        return objRet;
    }

    //public static void sendEmail_NormalMail(Email_Stack objEmailStack)
    //{
    //    try
    //    {
    //        if (System.Configuration.ConfigurationManager.AppSettings["emailLive"] == "0")
    //        {
    //            objEmailStack.ToAddress = System.Configuration.ConfigurationManager.AppSettings["demoEmail"];
    //            if (objEmailStack.ToCC != null && objEmailStack.ToCC != "")
    //                objEmailStack.ToCC = System.Configuration.ConfigurationManager.AppSettings["demoEmail"];
    //            if (objEmailStack.ToBCC != null && objEmailStack.ToBCC != "")
    //                objEmailStack.ToBCC = System.Configuration.ConfigurationManager.AppSettings["demoEmail"];
    //        }
    //        MailMessage mm;
    //        MailAddress maTo;

    //        int intDemoServer = int.Parse(System.Configuration.ConfigurationManager.AppSettings["DemoServer"].ToString());


    //        if (intDemoServer == 1)
    //        {
    //            objEmailStack.Body = objEmailStack.Body + "<br /><br /> Remarks : " + objEmailStack.Remarks;
    //        }
    //        mm = new MailMessage();
    //        mm.Subject = objEmailStack.Subject;
    //        mm.Body = objEmailStack.Body;
    //        mm.IsBodyHtml = true;
    //        if (objEmailStack.FromAddress == null || objEmailStack.FromAddress == "")
    //        {
    //            throw (new Exception("From Email ID is missing for EmailStackID:" + objEmailStack.PK));
    //        }
    //        mm.From = new MailAddress(objEmailStack.FromAddress, "DSK Legal");
    //        if (objEmailStack.ToAddress.Trim(new char[] { ',' }).Contains(","))
    //        {
    //            string[] arrToEmail = objEmailStack.ToAddress.Trim(new char[] { ',' }).Split(new char[] { ',' });
    //            string[] arrToName = null;
    //            if (objEmailStack.ToName != null && objEmailStack.ToName.ToString().Trim(new char[] { ',' }).Contains(","))
    //                arrToName = objEmailStack.ToName.Trim(new char[] { ',' }).Split(new char[] { ',' });
    //            for (int i = 0; i < arrToEmail.Length; i++)
    //            {
    //                mm.To.Add(new MailAddress(arrToEmail[i], ((arrToEmail.Length == 1 && arrToName != null && arrToName.Length > i) ? arrToName[i] : "")));
    //            }
    //        }
    //        else
    //        {
    //            maTo = new MailAddress(objEmailStack.ToAddress, (objEmailStack.ToName == null ? "" : objEmailStack.ToName));
    //            mm.To.Add(maTo);
    //        }
    //        if (objEmailStack.ToCC != null && objEmailStack.ToCC != "")
    //        {
    //            if (objEmailStack.ToCC.Trim(new char[] { ',' }).Contains(","))
    //            {
    //                string[] arrToEmail = objEmailStack.ToCC.Trim(new char[] { ',' }).Split(new char[] { ',' });
    //                string[] arrToName = null;
    //                if (objEmailStack.ToCCName != null && objEmailStack.ToCCName.Trim(new char[] { ',' }).ToString().Contains(","))
    //                    arrToName = objEmailStack.ToCCName.Trim(new char[] { ',' }).Split(new char[] { ',' });
    //                for (int i = 0; i < arrToEmail.Length; i++)
    //                {
    //                    String strName = "";
    //                    if (arrToEmail.Length == 1 && arrToName != null && i < arrToName.Length)
    //                    {
    //                        strName = arrToName[i];
    //                    }
    //                    mm.CC.Add(new MailAddress(arrToEmail[i], strName));
    //                }
    //            }
    //            else
    //                mm.CC.Add(new MailAddress(objEmailStack.ToCC, (objEmailStack.ToCCName == null ? "" : objEmailStack.ToCCName)));
    //        }

    //        if (objEmailStack.ToBCC != null && objEmailStack.ToBCC != "")
    //        {
    //            if (objEmailStack.ToBCC.Trim(new char[] { ',' }).Contains(","))
    //            {
    //                string[] arrToEmail = objEmailStack.ToBCC.Trim(new char[] { ',' }).Split(new char[] { ',' });
    //                string[] arrToName = null;
    //                if (objEmailStack.ToBCCName != null && objEmailStack.ToBCCName.Trim(new char[] { ',' }).ToString().Contains(","))
    //                    arrToName = objEmailStack.ToBCCName.Trim(new char[] { ',' }).Split(new char[] { ',' });
    //                for (int i = 0; i < arrToEmail.Length; i++)
    //                {
    //                    String strName = "";
    //                    if (arrToEmail.Length == 1 && arrToName != null && i < arrToName.Length)
    //                    {
    //                        strName = arrToName[i];
    //                    }
    //                    mm.Bcc.Add(new MailAddress(arrToEmail[i], strName));
    //                }
    //            }
    //            else
    //                mm.Bcc.Add(new MailAddress(objEmailStack.ToBCC, (objEmailStack.ToBCCName == null ? "" : objEmailStack.ToBCCName)));
    //        }

    //        if (objEmailStack.AttachmentPath != null && objEmailStack.AttachmentPath != "")
    //        {
    //            string[] arrattachPath = objEmailStack.AttachmentPath.Trim(new char[] { '*' }).Split(new[] { '*' });
    //            for (int i = 0; i < arrattachPath.Length; i++)
    //            {
    //                if (File.Exists(arrattachPath[i].Replace("/", "\\")))
    //                {
    //                    System.Net.Mail.Attachment mattach = new System.Net.Mail.Attachment(arrattachPath[i].Replace("/", "\\"));
    //                    mm.Attachments.Add(mattach);
    //                }
    //            }
    //        }

    //        SmtpClient smtp = new SmtpClient();
    //        smtp.EnableSsl = true;
    //        smtp.Send(mm);
    //        //new DAL_EmailStack().DAUpdateEmailStatus(objEmailStack);
    //    }
    //    catch (Exception Ex)
    //    {
    //        //new DAL_EmailStack().DAUpdateEmailCount(objEmailStack);
    //        //CommonUtil.Elmah_SignalException(Ex, HttpContext.Current, "Global");
    //        //new CommonUtil().CreateErrorLogFile("Email Error MailID =" + objEmailStack.MailID, Ex);
    //    }
    //}


}